<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/10/28 14:46
 * Modified Time: 2019/10/28 14:46
 * Version: 2.0
 */

namespace App\Modules\MemberCard\Repositores;


use App\Exceptions\NotFoundException;
use App\Models\MemberCardOrder;
use App\Modules\MemberCard\Criterias\GetOrderDetailBillListByOrderIdsCriteria;
use Flower\Core\Repository\Eloquent\BaseRepository;

class MemberCardOrderRepository extends BaseRepository
{
	public function model()
	{
		return MemberCardOrder::class;
	}

	public function createMemberCardOrder($store_id, $member_id, $category, $price, $real_price, $status)
	{
		$data = [
			'store_id'   => $store_id,
			'member_id'  => $member_id,
			'category'   => $category,
			'price'      => $price,
			'real_price' => $real_price,
			'status'     => $status
		];

		return $this->create($data);
	}


	/**
	 * 检测是否存在
	 * @param $id
	 * @return mixed
	 * @throws NotFoundException
	 */
	public function isExited($id)
	{
		$info = $this->find($id);
		if (empty($info)) {
			throw new NotFoundException(['msg' => '您要查找的信息不存在！']);
		}
		return $info;
	}

	/**
	 * 获取订单列表
	 * @param $orderIds
	 * @return mixed
	 * @throws \Flower\Core\Repository\Exceptions\RepositoryException
	 */
	public function getOrderListByIds($orderIds)
	{
		return $this->pushCriteria(new GetOrderDetailBillListByOrderIdsCriteria($orderIds))->get()->toArray();
	}

	/**
	 * 获取订单详情
	 * @param $orderIds
	 * @return mixed
	 * @throws \Flower\Core\Repository\Exceptions\RepositoryException
	 */
	public function getOrderDetailInfo($orderIds)
	{
		return $this->pushCriteria(new GetOrderDetailBillListByOrderIdsCriteria($orderIds))->first();
	}


}